/*
 * jiyan
 */
package com.jiyan.material.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.redis.core.RedisTemplate;
import springfox.documentation.annotations.ApiIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import com.rzhkj.core.tools.redis.RedisUtils;
import com.rzhkj.core.tools.StringTools;
import com.rzhkj.core.entity.BeanRet;
import com.rzhkj.core.entity.Page;
import com.jiyan.core.base.BaseCtrl;
import com.jiyan.material.facade.MaterialCategorySV;
import com.jiyan.material.entity.MaterialCategory;



/**
 * 供应类型
 *
 * @author jiyan
 */
@Controller
@RequestMapping("/materialCategory")
@Api(value = "供应类型控制器", description = "供应类型控制器")
public class MaterialCategoryCtrl extends BaseCtrl {
 private final static Logger logger = LoggerFactory.getLogger(MaterialCategoryCtrl.class);

    @Resource
    protected RedisTemplate<String, Object> redisTemplate;
    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MaterialCategorySV materialCategorySV;



    /**
     * 查询供应类型详情信息
     *
     * @param id 
     * @return BeanRet
     */
    @ApiOperation(value = "查询供应类型详情信息", notes = "查询供应类型详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/loadById")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if(id == null){
          return BeanRet.create();
        }
        
        MaterialCategory materialCategory = materialCategorySV.load(id);
        logger.info(JSON.toJSONString(materialCategory));
        return BeanRet.create(true, "查询详情信息", materialCategory);
    }


    /**
     * 查询供应类型详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询供应类型详情信息", notes = "查询供应类型详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/loadByCode")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if(StringTools.isEmpty(code)){
          return BeanRet.create();
        }
        
        MaterialCategory materialCategory = materialCategorySV.loadByCode(code);
        logger.info(JSON.toJSONString(materialCategory));
        return BeanRet.create(true, "查询详情信息", materialCategory);
    }



    /**
     * 查询供应类型信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询供应类型信息集合", notes = "查询供应类型信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore MaterialCategory materialCategory,@ApiIgnore Page<MaterialCategory> page) {
        if (page == null) {
                return BeanRet.create(false, "分页对象不能为空");
        }
        page.setParams(JSON.parseObject(JSON.toJSONString(materialCategory)));
        page = materialCategorySV.getList(page);
        return BeanRet.create(true, "", page);
    }

    /**
     * 创建供应类型
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建供应类型", notes = "创建供应类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "编码", paramType = "query", required = true)
    })
    @PostMapping("/save")
    @ResponseBody
    public BeanRet save(@ApiIgnore MaterialCategory materialCategory) {
        materialCategorySV.save(materialCategory);
        return BeanRet.create(true, "保存成功");
    }


    /**
     * 修改供应类型
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改供应类型", notes = "修改供应类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "编码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore MaterialCategory materialCategory) {
        materialCategorySV.update(materialCategory);
        return BeanRet.create(true, "修改成功");
    }

    /**
     * 删除供应类型
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除供应类型", notes = "删除供应类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", required = true)
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        if(id==null){
          return BeanRet.create(false,"不能为空");
        }
        if(code==null){
          return BeanRet.create(false,"编码不能为空");
        }
        materialCategorySV.delete(id,code);
        return BeanRet.create(true, "删除MaterialCategory成功");
    }

}
